#!/usr/bin/env bash
#----------------------------
#weixin reboot script
#author chenhuachao
#desc 重启uwsgi 脚本 用法：sh deplay.sh
#----------------------------
proname="TDSD_Server"
function uwsgistatus(){
    uwsgi_s=`ps -ef|grep $proname|grep -v grep|wc -l`
    if [ $uwsgi_s -gt 0 ]
    then
        return 126
    else
    return 127
    fi

}
function stop_uwsgi(){

        ps -ef|grep $proname|grep -v grep |awk '{print $2}'|xargs kill -9
}

function start_uwsgi(){
        uwsgi --procname $proname -x TDSD_server.xml &
        echo "已启动uwsgi进程"
}

uwsgistatus
if [ $? -eq 126 ]
then
    echo "准备杀死uwsig进程"
    ps -ef|grep $proname|grep -v grep |awk '{print $2}'|xargs kill -9
    uwsgistatus
    if [ $? -eq 126 ]
    then
       echo "未杀死uwsgi"
       stop_uwsgi
       start_uwsgi
    else
       echo "uwsgi is stop"
       start_uwsgi
    fi
else
    start_uwsgi
fi